# -*- coding: utf-8 -*-

from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dwd.oms.dwd_oms_order_dt import jms_dwd__dwd_oms_order_dt
from jms.dim.dim_lmdm_sys_network import jms_dim__dim_lmdm_sys_network
from jms.dim.dim_lmdm_sys_network_expand import jms_dim__dim_lmdm_sys_network_expand
from jms.dws.dws_actual_aging_sign_dt import jms_dws__dws_actual_aging_sign_dt
from jms.dws.dws_actual_taking_dt import jms_dws__dws_actual_taking_dt
from jms.ods.tms.yl_tms_branch_shipment import jms_ods__tms_branch_shipment
from jms.ods.tab.tab_valid_data import jms_ods__tab_valid_data
from jms.ods.tab.tab_end_piece import jms_ods__tab_end_piece
from jms.dim.dim_lmdm_sys_first_code import jms_dim__dim_lmdm_sys_first_code
from jms.dim.dim_lmdm_sys_second_code import jms_dim__dim_lmdm_sys_second_code


jms_dm__dm_waybill_prescription_reach_details_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_waybill_prescription_reach_details_dt',
    email=['zhangqinglin@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_waybill_prescription_reach_details_dt_{{ execution_date | date_add(1) | cst_ds }}',
    # sla=timedelta(hours=7),
    driver_memory='30G',
    executor_memory='10G',
    executor_cores=8,
    num_executors=40,
    pool_slots=8,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '6G',  # 堆外内存
          'spark.sql.shuffle.partitions': 1800
          },
    # jars='hdfs:///user/spark/work/dm/hejian/dm__dm_waybill_prescription_reach_details/common-1.0-SNAPSHOT.jar',  # 依赖 jar 包
    jars='hdfs:///scheduler/jms/spark/zql/dm__dm_waybill_prescription_reach_details/common-1.0-SNAPSHOT.jar',
    # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.export.WaybillPrescriptionReachDetailsNew',  # spark 主类
    # application='hdfs:///user/spark/work/dm/hejian/dm__dm_waybill_prescription_reach_details/original-jobs-1.0-SNAPSHOT.jar',  # spark jar 包
    application='hdfs:///scheduler/jms/spark/zql/dm__dm_waybill_prescription_reach_details/original-jobs-1.0-SNAPSHOT.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_ds }}'],
    execution_timeout=timedelta(hours=2),
)

jms_dm__dm_waybill_prescription_reach_details_dt << [
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    jms_dwd__dwd_oms_order_dt,
    jms_dim__dim_lmdm_sys_network,
    jms_dim__dim_lmdm_sys_network_expand,
    jms_dws__dws_actual_aging_sign_dt,
    jms_dws__dws_actual_taking_dt,
    jms_ods__tms_branch_shipment,
    jms_ods__tab_valid_data,
    jms_ods__tab_end_piece,
    jms_dim__dim_lmdm_sys_first_code,
    jms_dim__dim_lmdm_sys_second_code
]
